import React, { Component } from 'react';
import axios from 'axios'
import { Link } from 'react-router-dom'
class HotCompany extends Component {
  constructor (props) {
    super (props)
    this.showAll = this.showAll.bind(this)
    this.state = {
      hotCompanyList: []
    }
  }
  showAll (obj) {
    let storge =  window.localStorage;
    storge.hotComList = JSON.stringify(obj)
    console.log(storge.hotComList)
  }
  componentWillMount () {
    const that = this
    let content = []
    axios.get('http://80days.lockinchina.com/apib/eightyDay/companyList')
      .then(function (res) {
        const data = res.data 
        if(data.code === 200){
          content = data.data
        }
        that.setState(() => ({
          hotCompanyList: content
        }))
      })
  }
  render () {
    return (
      <div>
        {this.getCompanyList()}
      </div>
    )
  }
  getCompanyList() {
    const list = this.state.hotCompanyList;
    return list.map((item, index) => {
      return (
        <div
          style={{display: (item.list.length === 0 ? "none" : "block")}} 
          key={item.id} 
          className="hot-company m-b-3"
        >
          <div className="hot-title">
            <p>{item.title}</p>
            <Link to="/hotcompanylist"  >
              <button 
                onClick={() => this.showAll(item)}
                style={{display: (item.list.length > 8 ? "block" : "none")}}
              >
                查看更多
              </button>
            </Link>
          </div>
          <ul className="hot-im-list">
            {
              item.list.map((child, index) => {
                return (
                  index >= 8
                  ? 
                  false
                  :
                  <li 
                   key={child.id}
                   onClick={()=> window.location="http://job.lockinchina.com/company/companyDetail?companyId="+child.companyId+""}
                  >
                    <div>
                        <div className="im">
                          <img alt="" src={child.imageUrl} />
                        </div>
                        <img alt="" src={require('../../static/images/png.png')} />
                    </div>
                  </li>
                )
              })
            }
            
          </ul>
        </div>
      )
    })
  }
}

export default HotCompany